import { Application } from 'egg';

export default (app: Application) => {
  const { controller, router, middleware } = app;

  const verifyToken = middleware.verifytoken();

  router.get('/', controller.home.index);

  // 注册用户
  router.post('/user/register', controller.user.register);
  // 登录用户
  router.post('/user/login', controller.user.login);
  // 查询用户列表
  router.get('/user/getUserPages', verifyToken, controller.user.getUserPages);
  // 查询单个用户信息
  router.get('/user/:username', verifyToken, controller.user.findUser);


  // 上传商品
  router.post('/good/create', controller.good.create);
  // 更新商品
  router.post('/good/update/:goodId', controller.good.create);
  // 获取商品列表
  router.get('/good/list', controller.good.getGoods);
  // 搜索商品
  router.get('/good/search', controller.good.searchGoods);
  // 通过ID获取商品
  router.get('/good/:id', controller.good.findGoodById);
  // 删除商品
  router.delete('/good/:goodId', verifyToken, controller.good.removeGood);

  // 创建店铺
  router.post('/shop/create', verifyToken, controller.shop.create);
  // 更新店铺
  router.post('/shop/update/:shopId', verifyToken, controller.shop.update);
  // 通过id获取店铺数据
  router.get('/shop/:shopId', verifyToken, controller.shop.getShopById);
  // 删除店铺
  router.delete('/shop/:shopId', verifyToken, controller.shop.removeShop);

  // 创建分类
  router.post('/category/create', verifyToken, controller.category.create);
  // 获取分类
  router.get('/category', controller.category.find);
};
